package com.learn.project2.service.wx.brand;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.learn.project2.bean.MarketBrand;
import com.learn.project2.bean.MarketBrandExample;
import com.learn.project2.mapper.MarketBrandMapper;
import com.learn.project2.model.vo.wx.brand.BrandListVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @description：
 * @author： Yj
 * @create： 2022/01/09
 **/
@Service
public class BrandServiceImpl2 implements BrandService2{
    @Autowired
    MarketBrandMapper marketBrandMapper;
    @Override
    public BrandListVO selectBrand(Integer page, Integer limit) {
        //开启分页
        PageHelper.startPage(page,limit);
        MarketBrandExample brandExample = new MarketBrandExample();
        brandExample.createCriteria().andDeletedEqualTo(false);
        List<MarketBrand> marketBrands = marketBrandMapper.selectByExample(brandExample);

        PageInfo<MarketBrand> pageInfo = new PageInfo<>(marketBrands);
        long total = pageInfo.getTotal();
        int pages = pageInfo.getPages();

        BrandListVO brandListVO = new BrandListVO();
        brandListVO.setLimit(limit);
        brandListVO.setList(marketBrands);
        brandListVO.setPage(page);
        brandListVO.setPages(pages);
        brandListVO.setTotal((int) total);
        return brandListVO;
    }

    @Override
    public MarketBrand selectDetailBrand(Integer id) {
        MarketBrand marketBrand = marketBrandMapper.selectByPrimaryKey(id);
        return marketBrand;
    }
}
